package com.chare.Controller;

import com.chare.pojo.Admin;
import com.chare.pojo.RespBean;
import com.chare.pojo.Role;
import com.chare.service.IAdminRoleService;
import com.chare.service.IAdminService;
import com.chare.service.IAppraiseService;
import com.chare.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shi
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/system/admin")
public class AdminController {
    @Autowired
    private IAdminService adminService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IAdminRoleService adminRoleService;
@ApiModelProperty("获得所有操作员列表")
    @GetMapping("/getAllAdmins")
    public List<Admin> getAllAdmin(String keywords)
{

  return   adminService.getAllAdmin(keywords);
}
@ApiModelProperty("更新操作员")
    @PutMapping("/")
    public RespBean update(Admin admin)
{
    if(adminService.updateById(admin))
    {
        return RespBean.success("更新成功");
    } return RespBean.success("更新失败");
}
@ApiModelProperty("删除操作员")
    @DeleteMapping("/{id}")
    public  RespBean deleteAdmin(@PathVariable Integer id)
{
    if(adminService.removeById(id))
    {
        return RespBean.success("删除成功");
    }return RespBean.success("删除失败");
}
@ApiModelProperty("获得所有角色")
    @GetMapping("/roles")
    public  List<Role> listRole()
{
return roleService.list();

}
@ApiModelProperty("修改操作员的角色")
    @PutMapping("/updateAdminRole")
    public  RespBean updateRole(Integer adminId,Integer [] rids)
{
return     adminRoleService.updateRole(adminId,rids);
}
}
